﻿using AutoMapper;
using LeEdu.DAL.DataAccess;
using LeEdu.DTO;
using LeEdu.IDAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LeEdu.Service
{
    /// <summary>
    /// 课程服务类
    /// </summary>
    public class CourseService
    {
        private ICourseDAL courseDAL;
        public CourseService()
        {
            courseDAL = new CourseDAL();
        }

        public bool AddCourse(Entity.Course course)
        {
           var courseDTO= Mapper.Map<DTO.Course>(course);
           return courseDAL.AddCourse(courseDTO);
        }
        public bool DelCourse(Guid cid)
        {            
            return courseDAL.DelCourse(cid);
        }
        public Course GetCourseById(Guid cid)
        {
            return courseDAL.GetCourseById(cid);
        }

        public bool EditCourse(Course course)
        {
            return courseDAL.EditCourse(course);
        }

        public List<Entity.Course> GetCourses(int pageIndex,int pageSize,out long totalSize)
        {
            var courses= courseDAL.GetCourses(pageIndex, pageSize, out totalSize);
            var rtv= Mapper.Map<List<DTO.Course>,List<Entity.Course>>(courses);
            return rtv;
        }

        public List<Entity.Course> GetCoursesList()
        {
            var courses = courseDAL.GetCoursesList();
            var rtv = Mapper.Map<List<DTO.Course>, List<Entity.Course>>(courses);
            return rtv;
             
        }
    }
}
